package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.AirQualityIndex;
import com.qf.exception.AirException;
import com.qf.mapper.AirQualityIndexMapper;
import com.qf.service.AirQualityIndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ASUS
 * @version V1.0
 * @Project work
 * @Package com.qf.mapper.service.impl
 * @Date 2021/9/30 14:44
 */
@Service
@Slf4j
public class AirQualityIndexServiceImpl implements AirQualityIndexService {

    @Autowired
    private AirQualityIndexMapper airQualityIndexMapper;

    @Override
    public void insert(AirQualityIndex airQualityIndex) {
        int i = airQualityIndexMapper.insertSelective(airQualityIndex);
        if(i != 1){
            log.error("【添加空气质量信息】  添加失败！ airQualityIndex = {}",airQualityIndex);
            throw new AirException(23,"【添加空气质量信息】  添加失败");
        }
    }

    @Override
    public void updateById(AirQualityIndex airQualityIndex) {
        int i = airQualityIndexMapper.updateByPrimaryKeySelective(airQualityIndex);
        if(i != 1){
            log.error("【修改空气质量信息】  修改失败！ airQualityIndex = {}",airQualityIndex);
            throw new AirException(24,"【修改空气质量信息】  修改失败");
        }
    }

    @Override
    public void deleteById(Integer id) {
        int i = airQualityIndexMapper.deleteByPrimaryKey(id);
        if(i != 1){
            throw new AirException(25,"【删除空气质量信息】  删除失败");
        }
    }

    @Override
    public AirQualityIndex findById(Integer id) {
        return airQualityIndexMapper.findById(id);
    }

    @Override
    public PageInfo<AirQualityIndex> findByDistrictIdAndPage(Integer page, Integer rows, Integer districtId) {
        PageHelper.startPage(page,rows);
        List<AirQualityIndex> airList = airQualityIndexMapper.findByDistrictId(districtId);
        PageInfo<AirQualityIndex> pageInfo = new PageInfo<>(airList);
        return pageInfo;
    }
}
